package biznussoft.metercor;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.MenuItemCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import biznussoft.metercor.fragments.InventoryFragment;
import biznussoft.metercor.fragments.Scanfragment;
import biznussoft.metercor.fragments.StockTransferDetails;
import biznussoft.metercor.fragments.WarehouseDetailsFragment;
import biznussoft.metercor.listeners.GlobalListener;
import biznussoft.metercor.listeners.InventoryListener;

import com.salesforce.androidsdk.app.SalesforceSDKManager;

public class InventoryActivity extends BaseActivity implements InventoryListener,GlobalListener{

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.stock_activity);
	}

	@Override
	public void onWarehouseClicked(final int position,final String Category) {/*
		// TODO Auto-generated method stub

		if(position >= 0){                
			WarehouseDetailsFragment newFragment = new WarehouseDetailsFragment();
			FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
			transaction.replace(R.id.inventoryviewer, newFragment);
			transaction.addToBackStack(null);
			transaction.commit();
			new Handler().postDelayed(new Runnable() {                      
				@Override
				public void run() {
					WarehouseDetailsFragment warehouseFragment = (WarehouseDetailsFragment) getSupportFragmentManager().findFragmentById(R.id.inventoryviewer);
					warehouseFragment.getWarehouseDetails(position);
				}
			}, 1000);
		}
		
		
	*/
		if(position >= 0){ 
			StockTransferDetails newFragment = new StockTransferDetails();
			FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
			transaction.replace(R.id.stocktransferview, newFragment);
			transaction.addToBackStack(null);
			transaction.commit();
			
			new Handler().postDelayed(new Runnable() {                      
				@Override
				public void run() {
					StockTransferDetails warehouseFragment = (StockTransferDetails) getSupportFragmentManager().findFragmentById(R.id.stocktransferview);
//					warehouseFragment.getWarehouseDetails(Category,"445");
				}
			}, 1000);
		}
		if(position >= 1){ 
			StockTransferDetails newFragment = new StockTransferDetails();
			FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
			transaction.replace(R.id.stocktransferview, newFragment);
			transaction.addToBackStack(null);
			transaction.commit();
			
			new Handler().postDelayed(new Runnable() {                      
				@Override
				public void run() {
					StockTransferDetails warehouseFragment = (StockTransferDetails) getSupportFragmentManager().findFragmentById(R.id.stocktransferview);
//					warehouseFragment.getWarehouseDetails(Category,"10");
				}
			}, 1000);
		}
			
			
		
	}

	@Override
	public void onCategoryClicked(int position) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onNewContact(String[] args) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onGetContacts(final int position, final String category) {
		// TODO Auto-generated method stub
		

		if(!category.equalsIgnoreCase("SiteInventory")){

			InventoryFragment newFragment = new InventoryFragment();
			FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
			transaction.replace(R.id.inventoryviewer, newFragment);
			transaction.addToBackStack(null);
			transaction.commit();

			new Handler().postDelayed(new Runnable() {                      
				@Override
				public void run() {
					InventoryFragment warehouseFragment = (InventoryFragment) getSupportFragmentManager().findFragmentById(R.id.inventoryviewer);
					warehouseFragment.showInventory(category);
				}
			}, 1000);
		}
		else{
			InventoryFragment newFragment = new InventoryFragment();
			FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
			transaction.replace(R.id.inventoryviewer, newFragment);
			transaction.addToBackStack(null);
			transaction.commit();
			
			new Handler().postDelayed(new Runnable() {                      
				@Override
				public void run() {
					InventoryFragment warehouseFragment = (InventoryFragment) getSupportFragmentManager().findFragmentById(R.id.inventoryviewer);
					warehouseFragment.getInventoryDetails(position);
				}
			}, 1000);

		}
	}

	@Override
	public void getSignature(final String base64) {
		// TODO Auto-generated method stub
		Scanfragment newFragment = new Scanfragment();
		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
		transaction.replace(R.id.stocktransferview, newFragment);
		transaction.addToBackStack(null);
		transaction.commit();
		
		
		
		
		new Handler().postDelayed(new Runnable() {                      
			@Override
			public void run() {
				Scanfragment warehouseFragment = (Scanfragment) getSupportFragmentManager().findFragmentById(R.id.stocktransferview);
				warehouseFragment.getEdit(base64);
			}
		}, 1000);
	}

	@Override
	public void displayFields(int position, String category) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onServiceClicked(int position) {
		// TODO Auto-generated method stub
		
	}

}
